<?php

namespace AdminBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use AdminBundle\Utility\Constant;

class TaskTemplateType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', TextType::class, [
            'label' => '名称',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请输入名称',
                'class' => Constant::INPUT_ATTR_CLASS],
            'required' => true,
        ])->add('note', TextareaType::class, [
            'label' => '注释',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请输入注释',
                'class' => Constant::INPUT_ATTR_CLASS],
            'required' => false,
            'empty_data' => '',
        ])->add('isEnabled', CheckboxType::class, array(
                'label' => '启用',
                'label_attr' => Constant::LABEL_ATTR_DEFAULT,
                'attr' => [
                    'class' => 'ace ace-switch ace-switch-5',],
                'required' => false,
            )
        )->add('uri', TextType::class, [
            'label' => '资源定位符',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请输入组资源定位符',
                'class' => Constant::INPUT_ATTR_CLASS],
            'required' => true,
            'empty_data' => '',
        ])->add('method', TextType::class, [
            'label' => '方法',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请输入方法',
                'class' => Constant::INPUT_ATTR_CLASS],
            'required' => false,
            'empty_data' => '',
        ])->add('action', TextType::class, [
            'label' => '动作',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请输入动作',
                'class' => Constant::INPUT_ATTR_CLASS],
            'required' => false,
            'empty_data' => '',
        ])->add('param', TextareaType::class, [
            'label' => '参数',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请输入参数',
                'class' => Constant::INPUT_ATTR_CLASS],
            'required' => false,
            'empty_data' => '',
        ])
        ;
//        $builder->add('name')->add('note')->add('isEnabled')->add('creator')->add('ip')->add('ctime')->add('uri')->add('method')->add('action')->add('param');
    }
    
    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AdminBundle\Entity\TaskTemplate'
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'adminbundle_tasktemplate';
    }


}
